package com.ycrlkj.android.modulesbase.libbase.init;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.Gravity;
import java.util.Collections;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.startup.Initializer;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.ycrlkj.android.modulesbase.libbase.constant.BaseSettingsConstant;
import com.ycrlkj.android.modulesbase.libbase.utils.Logger;
import com.ycrlkj.android.modulesbase.libbase.utils.PropertiesUtil;

public class LibBaseInitializer implements Initializer<Object> {

    @NonNull
    @Override
    public Object create(@NonNull Context context) {

        // 获取配置信息，进行一些初始化的设置
        PropertiesUtil.init(context);
        String tag = PropertiesUtil.getProperty("tag");
        String isShowLog = PropertiesUtil.getProperty("isShowLog");

        Logger.init(TextUtils.isEmpty(tag) ? "TAG" : tag, !TextUtils.equals(isShowLog, "false"));

        SPStaticUtils.setDefaultSPUtils(SPUtils.getInstance(BaseSettingsConstant.SP_NAME));

        initToast();

        return null;
    }

    //Toast设置统一样式
    public void initToast() {
        ToastUtils defaultMarker = ToastUtils.getDefaultMaker();
        defaultMarker.setGravity(Gravity.CENTER,0,0);
        defaultMarker.setBgColor(Color.BLACK);
        defaultMarker.setTextColor(Color.WHITE);
    }

    @NonNull
    @Override
    public List<Class<? extends Initializer<?>>> dependencies() {
        return Collections.emptyList();
    }

}